package com.alks.entity.data.page;

import com.alks.entity.exception.ServiceErrorException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

/**
 * @author MS
 * @since 2024/12/21上午11:27
 */
@Data
public class OrderParam extends PageParam {

    @ApiModelProperty(value = "品牌")
    private String orderFiled;

    @ApiModelProperty(value = "指令")
    private Integer orderType;

    public String getOrderFiled() {
        sqlCheck(this.orderFiled);
        return this.orderFiled;
    }


    /**
     * SQL注入检测(在SQL中搭配``使用)
     * @param sql 要检测的SQL语句
     */
    public static void sqlCheck(String sql) {
        if (StringUtils.isBlank(sql)){
            return;
        }
        // 检测注释符 -- 或 /* ... */
        boolean check1 = sql.contains("--");
        boolean check2 = Pattern.compile("/\\*.*?\\*/").matcher(sql).find();
        boolean check3 = sql.contains("`");
        boolean check4 = sql.contains(";");
        boolean check5 = sql.contains(" ");
        boolean check = (check1 || check2) && check3 && check4 && check5;
        if (check) {
            throw new ServiceErrorException("?");
        }
    }

}
